package tuiLayer;
import controlLayer.*;
import modelLayer.*;
import java.util.*;

public class ContractorUI
{
    private ContractorCtr contractorCtr;

    public ContractorUI(){
        contractorCtr = new ContractorCtr();
    }

    public void start(){
        mainMenuContractor();
    }

    private void mainMenuContractor(){
        boolean stop=false;
        while(!stop){
            int choice = writeMainMenuContractor();

            switch(choice){
                case 0:
                    stop = true;
                    break;             
                case 1:
                    createContractor();
                    break;
                case 2:
                    findContractor();
                    break;
                case 3:
                    updateContractor();
                    break;
                case 4:
                    deleteContractor();
                    break;
                default : System.out.println("Enter a valid choice");
            }
        }
    }

    private int writeMainMenuContractor(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\n*****contractor menu*****");
        System.out.println("(0) Back");
        System.out.println("(1) Create contractor");
        System.out.println("(2) Find contractor");
        System.out.println("(3) Update contractor");
        System.out.println("(4) Delete contractor ");
        System.out.println("\nType your choice");
        int choice= keyboard.nextInt();
        return choice;
    }

    private void createContractor(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Contractor creation---");
        System.out.println();
        
        System.out.println("Enter contractor's id:");
        int id = keyboard.nextInt();
        keyboard.nextLine();
        
        System.out.println("Enter contractor's name:");
        String name = keyboard.nextLine();
        
        System.out.println("Enter contractor's delivery time:");
        String deliveryTime = keyboard.nextLine();
        
        contractorCtr.createContractor(id, name, deliveryTime);
        System.out.println("Contractor successfully created!");
    }

    private void findContractor(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Contractor search---");
        System.out.println();
        System.out.println("Enter contractors id:");
        int id = keyboard.nextInt();

        Contractor cont =  contractorCtr.findContractor(id);
        System.out.println("--------------------------");
        System.out.println("ID:\t\t\t" + cont.getId());
        System.out.println("Name:\t\t\t" + cont.getName());
        System.out.println("Delivery time:\t\t" + cont.getDeliveryTime());
        System.out.println("--------------------------");
    }

    private void updateContractor(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Contractor update---");
        System.out.println();
        
        System.out.println("Enter contractor's id:");
        int id = keyboard.nextInt();
        keyboard.nextLine();
        
        System.out.println("Enter contractor's name:");
        String name = keyboard.nextLine();
        
        System.out.println("Enter contractor's delivery time:");
        String deliveryTime = keyboard.nextLine();
        
        
        
        contractorCtr.updateContractor(id, name, deliveryTime);
        System.out.println("Contractor successfully updated!");
    }

    private void deleteContractor(){
        Scanner keyboard = new Scanner(System.in);
        System.out.println("---Contractor removal---");
        System.out.println();

        System.out.println("Enter the contractor's id:");
        int id = keyboard.nextInt();

        contractorCtr.deleteContractor(id);
        System.out.println("Contractor successfuly deleted!");
    }
}